package com.telit.firecommand.service;

import com.alibaba.fastjson.JSONObject;
import com.telit.common.constant.SmsTemplateConstants;
import com.telit.common.util.AliSmsUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther amy
 * @Describe
 */
@Service
public class MsgService {

    @Value("${weather.address}")
    private String location;

    /**
     * 给值守人员发送需要判别短信：xxxx视频监控发现了xx地址的火情，请前往判别
     * @param mobileList
     * @param cameraName
     * @param address
     */
    public void pushFireAlarmConfirmSms(List<String> mobileList,String cameraName,String address){
        if(CollectionUtils.isEmpty(mobileList)){
            return;
        }

        mobileList.forEach(mobile->{
            Map<String,String> map = new HashMap<>();
            map.put("videoName",cameraName);
            map.put("address", address);
            // 短信模板：${address}地址发现了真实火情,请及时组织扑火工作
            try {
                AliSmsUtils.sendSms(mobile,JSONObject.toJSONString(map), SmsTemplateConstants.SMS_TEMPLATE_FIRE_ALARM_CONFIRM);
//            } catch (ClientException e) {
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }

}
